package cn.sdormitory.violative.form;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.lang.Assert;
import cn.sdormitory.common.utils.ContainerUtil;
import cn.sdormitory.violative.entity.ViolationClassInterval;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

@Data
public class ViolationClassIntervalSaveForm {


    @ApiModelProperty("课间违纪编号")
    private Long id;

    @ApiModelProperty("违纪图片列表")
    private List<String> images;

    @ApiModelProperty("班级编号")
    private Long classId;

    @ApiModelProperty("违纪类型")
    private Integer violationType;

    @ApiModelProperty("违纪巡查备注")
    private String note;

    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    @ApiModelProperty(value = "违纪时间")
    private Date violationTime;

    public ViolationClassInterval generateViolationClassInterval(){
        Assert.notEmpty(images,"课间违纪图片列表不能为空");
        Assert.notNull(classId,"课间违纪班级不能为空");
        return new ViolationClassInterval()
                .setId(id)
                .setClassId(classId)
                .setViolationType(violationType)
                .setNote(note)
                .setViolationTime(violationTime)
                .setCover(ContainerUtil.getFirst(images))
                .setImages(String.join(",", images))
                .initCreateAndModifyInfo();
    }
}
